<?php
class UsersController extends AppController {
	var $name = 'Users' ;
	var $aro = null ;
	var $aco = null ;
	var $uses = array ( 'User' , 'Group' ) ;
	public  $helpers = array ( 'Html');
	
	function index () 

	{
		
		echo "index action" ;
		
		exit () ;
	
	}
	function login () {
		$user = $this->user ;
		if ($user) {
			$this->autoRender = false ;
			$this->redirect ( "/" ) ;
		}
		
		if (empty ( $this->data ) == false) {
			
			if (($user = $this->User->validateLogin ( $this->data [ 'User' ] )) == true) {
				$this->Session->write ( 'Auth.user', $user ) ;
				$this->Session->setFlash ( __ ( "logged_in", true ) ) ;
				$this->autoRender = false ;
				$this->redirect ( $this->AclAuth->loginRedirect ) ;
			} else {
				$this->Session->setFlash ( __ ( "login_error", true ) ) ;
			}
		}
		
		$this->set ( "message", $this->Session->read ( 'Message' ) ) ;
	
	}
	function logout () {
		
		$this->Session->del ( "Auth" ) ;
		$this->controller->user = null ;
		$this->Session->setFlash ( __ ( "logged_out", true ) ) ;
		
		$this->autoRender = false ;
		$this->redirect ( 'login' ) ;
	}
	
	function edit () {
		echo "edit action" ;
		exit () ;
	}
	function register () {
		if (! isset ( $this->user ) || ! $this->user) {
			if (! empty ( $this->data )) {
				$this->User->data = $this->data ;
				if ($this->User->save ()) {
					
					$this->Session->setFlash ( __ ( "register_success", true ) . " your pass: " . $this->User->p4ss, null, null, "smessage" ) ;
					$this->User->p4ss = null ;
				} else {
					$this->Session->setFlash ( __ ( "register_unsuccess", true ), null, null, "usmessage" ) ;
				}
				
				$this->set ( "message", $this->Session->read ( 'Message' ) ) ;
			
			}
		} else {
			$this->autoRender = false ;
			$this->redirect ( "/" ) ;
		}
	}
}
?>